{% extends 'admin/base.html' %}

{% block title %}编辑用户 - 天气系统管理后台{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <h2>编辑用户</h2>
        <hr>
    </div>
</div>

<div class="row">
    <div class="col-12">
        <form method="post" enctype="multipart/form-data">
            <div class="mb-3">
                <label for="username" class="form-label">用户名</label>
                <input type="text" class="form-control" id="username" name="username" value="{{ user.username }}" required>
            </div>
            <div class="mb-3">
                <label for="email" class="form-label">邮箱</label>
                <input type="email" class="form-control" id="email" name="email" value="{{ user.email }}" required>
            </div>
            <div class="mb-3">
                <label for="phone" class="form-label">电话</label>
                <input type="text" class="form-control" id="phone" name="phone" value="{{ user.phone }}">
            </div>
            <div class="mb-3">
                <label for="bio" class="form-label">简介</label>
                <textarea class="form-control" id="bio" name="bio">{{ user.bio }}</textarea>
            </div>
            <div class="mb-3">
                <label for="location" class="form-label">位置</label>
                <select class="form-control" id="location" name="location">
                    <option value="" {% if not user.location %}selected{% endif %}>选择地区</option>
                    <option value="大陆地区" {% if user.location == '大陆地区' %}selected{% endif %}>大陆地区</option>
                    <option value="港澳台地区" {% if user.location == '港澳台地区' %}selected{% endif %}>港澳台地区</option>
                    <option value="海外" {% if user.location == '海外' %}selected{% endif %}>海外</option>
                </select>
            </div>
            <div class="mb-3">
                <label for="occupation" class="form-label">职业</label>
                <select class="form-control" id="occupation" name="occupation">
                    <option value="" {% if not user.occupation %}selected{% endif %}>选择职业</option>
                    <option value="气象工作者" {% if user.occupation == '气象工作者' %}selected{% endif %}>气象工作者</option>
                    <option value="研究人员" {% if user.occupation == '研究人员' %}selected{% endif %}>研究人员</option>
                    <option value="学生" {% if user.occupation == '学生' %}selected{% endif %}>学生</option>
                    <option value="教师" {% if user.occupation == '教师' %}selected{% endif %}>教师</option>
                    <option value="其他" {% if user.occupation == '其他' %}selected{% endif %}>其他</option>
                </select>
            </div>
            <div class="mb-3">
                <label for="avatar_file" class="form-label">头像</label>
                <input type="file" class="form-control" id="avatar_file" name="avatar_file">
            </div>

            <!-- 使用 Flexbox 居中按钮 -->
            <div class="d-flex justify-content-center">
                <button type="submit" class="btn btn-primary me-2">保存更改</button>
                <a href="{{ url_for('admin_users') }}" class="btn btn-secondary">返回用户列表</a>
            </div>
        </form>
    </div>
</div>
{% endblock %}